/*
 * @(#)CommonCodeDAOImpl.java $version 2013-3-1
 * 
 * Copyright 2013 NADO Group. All rights Reserved.
 * NADO PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nado.iims2.community.dao.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.nado.extensions.sql.SimpleSqlMapDaoSupport;
import com.nado.extensions.util.DataMap;
import com.nado.iims2.community.dao.CommonCodeDAO;
import com.nado.iims2.community.model.CategoryModel;
import com.nado.iims2.community.model.CodeModel;

/**
 * The Class CommonCodeDAOImpl.
 * 
 * @author nado
 */
@Repository("CommonCodeDAO")
public class CommonCodeDAOImpl extends SimpleSqlMapDaoSupport implements CommonCodeDAO {
	/** The Constants PREFIX. */
	private final static String PREFIX = "com.nado.iims2.community.code.";
	
	@Override
	public List<DataMap> selectCommonCategoryList() throws SQLException {
		return getSqlMapClient().queryForList(PREFIX + "selectCommonCategoryList");
	}

	@Override
	public int selectCommonCategoryListCount() throws SQLException {
		return (Integer) getSqlMapClient().queryForObject(PREFIX + "selectCommonCategoryListCount");
	}

	@Override
	public CategoryModel selectCommonCategoryDetail(String categoryCd) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("categoryCd", categoryCd);
		
		return (CategoryModel) getSqlMapClient().queryForObject(PREFIX + "selectCommonCategoryDetail", params);
	}

	@Override
	public List<DataMap> selectCommonCodeList(String categoryCd) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("categoryCd", categoryCd);
		
		return getSqlMapClient().queryForList(PREFIX + "selectCommonCodeList", params);
	}

	@Override
	public int selectCommonCodeListCount(String categoryCd) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("categoryCd", categoryCd);
		
		return (Integer) getSqlMapClient().queryForObject(PREFIX + "selectCommonCodeListCount", params);
	}

	@Override
	public CodeModel selectCommonCodeDetail(String categoryCd, String commonCd) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("categoryCd", categoryCd);
		params.put("commonCd", commonCd);
		
		return (CodeModel) getSqlMapClient().queryForObject(PREFIX + "selectCommonCodeDetail", params);
	}

	@Override
	public int updateCommonCategory(CategoryModel model) throws SQLException {
		return getSqlMapClient().update(PREFIX + "updateCommonCategory", model);
	}

	@Override
	public int deleteCommonCategory(String categoryCd) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("categoryCd", categoryCd);
		
		return getSqlMapClient().update(PREFIX + "deleteCommonCategory", params);
	}

	@Override
	public int updateCommonCode(CodeModel model) throws SQLException {
		return getSqlMapClient().update(PREFIX + "updateCommonCode", model);
	}

	@Override
	public int deleteCommonCode(String categoryCd, String commonCd) throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("categoryCd", categoryCd);
		params.put("commonCd", commonCd);
		
		return getSqlMapClient().update(PREFIX + "deleteCommonCode", params);
	}

	@Override
	public List<DataMap> selectCommonCodeAndNameList(String categoryCd)
			throws SQLException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("categoryCd", categoryCd);
		
		return getSqlMapClient().queryForList(PREFIX + "selectCommonCodeAndNameList", params);
	}

}
